//
//  YSCardImageItemFrame.m
//  Yueshi
//
//  Created by Northwan on 15/7/17.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSCardImageItemFrame.h"

@implementation YSCardImageItemFrame

-(void)setAdvert:(YSAdvert *)advert{
    _advert = advert;
    
    CGFloat imageHeight = (SCREENW-YSPublicXInset*2)/1.5;
    self.imageFrame = CGRectMake(YSPublicXInset, 0, SCREENW-YSPublicXInset*2, imageHeight);
    self.cellHeight = CGRectGetMaxY(self.imageFrame);
    
    if(!ISBLANK(advert.advertTitle)){
        self.imageFrame = CGRectMake(YSPublicXInset, 0, SCREENW-YSPublicXInset*2, imageHeight);
        self.cellHeight = CGRectGetMaxY(self.imageFrame);

        if(ISBLANK(advert.advertIcon)){//判断如果为空就隐藏icon
            //描述图标
            self.iconImageFrame = CGRectMake(YSPublicXInset,CGRectGetMaxY(self.imageFrame)+YSPublicXInset, 0, 21);
            //描述
            CGFloat descX = CGRectGetMaxX(self.iconImageFrame);
            CGFloat descY = CGRectGetMinY(self.iconImageFrame);
            CGSize descSize = [advert.advertTitle sizeWithFont:SYS_FONT(DescFont)];
            self.descFrame  = (CGRect){{descX, descY}, descSize};
        }else{
            //描述图标
            self.iconImageFrame =  CGRectMake(YSPublicXInset, CGRectGetMaxY(self.imageFrame)+YSPublicXInset, 21, 21);
            //描述
            CGFloat descX = CGRectGetMaxX(self.iconImageFrame) + 4;
            CGFloat descY = CGRectGetMinY(self.iconImageFrame);
            CGSize descSize = [advert.advertTitle sizeWithFont:SYS_FONT(DescFont)];
            self.descFrame  = (CGRect){{descX, descY}, descSize};
        }
        
        if(!ISBLANK(advert.advertText)){
            //子描述
            CGFloat subDescX = YSPublicXInset;
            CGFloat subDescY = CGRectGetMaxY(self.iconImageFrame) + 5;
            CGSize subDescSize = [advert.advertText sizeWithFont:SYS_FONT(SubDescFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, SubDescFont)];
            self.subDescFrame = (CGRect){{subDescX, subDescY}, subDescSize};
            self.cellHeight = CGRectGetMaxY(self.subDescFrame)+YSPublicXInset*2;
        }else{
            self.cellHeight = CGRectGetMaxY(self.iconImageFrame)+YSPublicXInset*2;
        }
        
    }else if(!ISBLANK(advert.advertText)){
        //子描述
        CGFloat subDescX = YSPublicXInset;
        CGFloat subDescY = CGRectGetMaxY(self.imageFrame) + YSPublicXInset;
        CGSize subDescSize = [advert.advertText sizeWithFont:SYS_FONT(SubDescFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, SubDescFont)];
        self.subDescFrame = (CGRect){{subDescX, subDescY}, subDescSize};
        
        self.cellHeight = CGRectGetMaxY(self.subDescFrame)+YSPublicXInset*2;
    }
    
    //自己的frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = SCREENW;
    CGFloat h = self.cellHeight;
    self.frame = CGRectMake(x, y, w, h);
}


@end
